package com.my12306.user.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * @Author:苏牧夕
 * @Date:2020/5/21 1:22
 * @Version 1.0
 */
@Configuration
public class TokenConfig {
    //生成tokend的密钥 -后期可以改为数据库获取
    private static String SINGING_KEY = "ilife";

//    @Bean
//    public TokenStore tokenStore(DataSource dataSource) {
//        return new JdbcTokenStore(dataSource);
//    }

    @Bean
    public TokenStore tokenStore(JwtAccessTokenConverter jwtAccessTokenConverter) {
        return new JwtTokenStore(jwtAccessTokenConverter);
    }

    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
        jwtAccessTokenConverter.setSigningKey(SINGING_KEY);
//        jwtAccessTokenConverter.setKeyPair();
        return jwtAccessTokenConverter;
    }
}
